Feature/assign shipment#32
Merged
Merged
Conversation
so, we can split apps easily with only changing the client
update from main
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements the "assign shipment" feature by extending vehicle functionality and creating a new assignment planning system that integrates shipments with vehicles. Key changes include:
- Updates to vehicle API and model tests with enhanced filtering and location update assertions.
- Addition of depot fields to the Vehicle model along with corresponding migrations and admin UI adjustments.
- Implementation of new assignment models, services, and views for planning and managing shipment assignments.
Reviewed Changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| fleet/tests/test_vehicle_api.py | Refactored integration tests for vehicle API endpoints with clearer naming and assertions |
| fleet/tests/test_vehicle.py | Updated unit tests for vehicle model, including default field value assertions |
| fleet/serializers/vehicle.py | Extended serializer fields to include depot-related attributes |
| fleet/models/core.py | Added depot_id, depot_latitude, and depot_longitude fields to the Vehicle model |
| fleet/migrations/0004_vehicle_depot_id.py & 0005_vehicle... | New migrations to support depot field additions |
| fleet/admin.py | Modified admin configuration to include new depot fields |
| assignment/views.py | Updated AssignmentViewSet to integrate shipment validation and assignment creation |
| assignment/tests/test_assignment_planner.py | Added tests for the new assignment planner functionality |
| assignment/services/mappers.py | Introduced mapping from Vehicle model to VRP input format |
| assignment/services/assignment_planner.py | New service to plan assignments using a VRP solver, mapping shipments to assignment items |
| assignment/serializers.py | Updated imports for the assignment serializer |
| assignment/models/assignment_item.py & assignment/models/assignment.py | New assignment models reflecting shipment items and assignment state |
| assignment/migrations/0001_initial.py | Updated migration reflecting the new assignment schema and inclusion of assignment items |
Comment on lines
+58
to
+64
| for i, route in enumerate(result["routes"]): | ||
| vehicle = self.vehicles[i] | ||
| logger.debug(f"Creating assignment for vehicle {vehicle.vehicle_id}, route: {route}") | ||
| assignment = Assignment.objects.create( | ||
| vehicle=vehicle, | ||
| total_load=sum( | ||
| vrp_input.demands[node] for node in route if vrp_input.demands[node] > 0 |
There was a problem hiding this comment.
[nitpick] Assuming that the order of routes from the VRP solver always matches the order of self.vehicles might be fragile. Consider adding a mapping mechanism to associate each route with the correct vehicle to improve robustness.
Suggested change
| for i, route in enumerate(result["routes"]): | |
| vehicle = self.vehicles[i] | |
| logger.debug(f"Creating assignment for vehicle {vehicle.vehicle_id}, route: {route}") | |
| assignment = Assignment.objects.create( | |
| vehicle=vehicle, | |
| total_load=sum( | |
| vrp_input.demands[node] for node in route if vrp_input.demands[node] > 0 | |
| for route in result["routes"]: | |
| vehicle_id = route["vehicle_id"] # Assuming each route includes a vehicle_id field | |
| vehicle = vehicle_map.get(vehicle_id) | |
| if not vehicle: | |
| logger.error(f"Vehicle with ID {vehicle_id} not found in vehicle_map.") | |
| raise Exception(f"Vehicle with ID {vehicle_id} not found.") | |
| logger.debug(f"Creating assignment for vehicle {vehicle.vehicle_id}, route: {route['nodes']}") | |
| assignment = Assignment.objects.create( | |
| vehicle=vehicle, | |
| total_load=sum( | |
| vrp_input.demands[node] for node in route["nodes"] if vrp_input.demands[node] > 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.